package com.gzy.exams.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gzy.exams.entity.Users;
import com.gzy.exams.mapper.UsersMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

@Service
public class UsersService extends ServiceImpl<UsersMapper, Users> {

    /**
     * 分页查询
     *
     * @param users 筛选条件
     * @param page 分页对象
     * @return 查询结果
     */
    public Page<Users> queryByPage(Users users, Page<Users> page) {
        QueryWrapper<Users> queryWrapper = new QueryWrapper<>();

        if (users.getUsername() != null && !users.getUsername().isEmpty()) {
            queryWrapper.like("username", users.getUsername());
        }

        if (users.getUserType() != null && !users.getUserType().isEmpty()) {
            queryWrapper.eq("user_type", users.getUserType());
        }

        // 添加更多筛选条件...

        return baseMapper.selectPage(page, queryWrapper);
    }
}
